package www.ym.com.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import www.ym.com.entity.Address;
import www.ym.com.entity.Staff;
import www.ym.com.mapper.AddressMapper;
import www.ym.com.service.AddressService;

@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public Page<Address> addressList(JSONObject jsonObject) {
        //当前页数
        Long pageNum = Long.valueOf(String.valueOf(jsonObject.get("pageNum")));
        //每页显示数
        Long pageSize = Long.valueOf(String.valueOf(jsonObject.get("pageSize")));
        //角色名称
//        String positionCode = String.valueOf(jsonObject.get("positionCode"));
//        //部门名称
//        String departmentName = String.valueOf(jsonObject.get("departmentName"));

        LambdaQueryWrapper<Address> wrapper = new LambdaQueryWrapper<>();

//        wrapper.eq(positionCode != "", Address::getPositionCode, positionCode);
        wrapper.orderByDesc(Address::getCreateTime);
        //进行分页查询-可跟条件
        Page<Address> urf = addressMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        System.out.println("数据为：" + urf.getRecords());
        System.out.println("总数为：" + urf.getTotal() + ",总页数为：" + urf.getPages());
        System.out.println("当前页为：" + urf.getCurrent() + ",每页限制：" + urf.getSize());
        return urf;
    }
}
